<?php
include("include/config.inc.php");
$totalJama      = 0;
$transArray     = array();
$totalUdhar     = 0;
$totalJamaUdhar = 0;
$jamaUdharWord  = 0;
$countTrans     = 0;
$total          = 0;
if($_GET['partyId'] > 0)
{
  $transQuery = "SELECT transactionId,date, jamaRupiya, jamaVigat, udhaarRupiya, udhaarVigat, udhaarVajan, udhaarBhav,
                        transaction.partyId, partyName , mobile1, city
                   FROM transaction
                   LEFT JOIN party ON transaction.partyId = party.partyId
                   LEFT JOIN city ON city.cityId = party.cityId
                  WHERE transaction.partyId = ".$_GET['partyId'];
  $transRes  = mysql_query($transQuery);
  while($transRow = mysql_fetch_array($transRes))
  {
    $transArray[$countTrans]['transactionId'] = $transRow['transactionId'];
    $transArray[$countTrans]['date']          = $transRow['date'];
    $transArray[$countTrans]['jamaRupiya']    = $transRow['jamaRupiya'];
    $transArray[$countTrans]['jamaVigat']     = $transRow['jamaVigat'];
    $transArray[$countTrans]['udhaarRupiya']  = $transRow['udhaarRupiya'];
    $transArray[$countTrans]['udhaarVigat']   = $transRow['udhaarVigat'];
    $transArray[$countTrans]['udhaarVajan']   = $transRow['udhaarVajan'];
    $transArray[$countTrans]['udhaarBhav']    = $transRow['udhaarBhav'];
    $transArray[$countTrans]['partyName']     = $transRow['partyName'];
    $transArray[$countTrans]['mobile1']       = $transRow['mobile1'];
    $transArray[$countTrans]['city']          = $transRow['city'];
    $totalJama                                += $transRow['jamaRupiya'];
    $totalUdhar                               += $transRow['udhaarRupiya'];
    $total                                    = $totalJama - $totalUdhar;
    $countTrans++;
  }
  $totalJamaUdhar = $totalJama - $totalUdhar;
  if($totalJamaUdhar > 0)
	{
		$jamaUdharWord = "Jama";
	}
	elseif($totalJamaUdhar < 0)
	{
		$jamaUdharWord = "Udhar";
	}

}
include("./bottom.php");
$smarty->assign('totalJama',$totalJama);
$smarty->assign('countTrans',$countTrans);
$smarty->assign('totalUdhar',$totalUdhar);
$smarty->assign('totalJamaUdhar',$totalJamaUdhar);
$smarty->assign('jamaUdharWord',$jamaUdharWord);
$smarty->assign('transArray',$transArray);
$smarty->assign('total',$total);
$smarty->display('ledgerAj.tpl');

?>